/**
 * xmlmodelconnector.h is part of cbs-framework.
 *
 * cbs-framework is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * cbs-framework is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with cbs-framework.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef XMLMODELCONNECTOR_H
#define XMLMODELCONNECTOR_H

#include "../../utils/connector/xmlconnector.h"

// Forward declarations.
class Model;
class Task;
class Resource;

class XmlModelConnector : public XmlConnector
{
public:

    XmlModelConnector( const std::string & a_file );

    virtual ~XmlModelConnector();

    Model * GetModel();

protected:

    virtual void ReadElement( QXmlStreamReader::TokenType a_type, QXmlStreamReader & a_xmlStream );

    virtual void HandleError( QXmlStreamReader & a_xmlStream );

private:

    // Fields.
    // -------

    Model * m_model;

    static const std::string MODEL_TAG;
    static const std::string TASK_TAG;
    static const std::string RESOURCE_TAG;
    static const std::string CONSTRAINT_TAG;
    static const std::string ID_ATTRIBUTE;
    static const std::string TYPE_ATTRIBUTE;
    static const std::string TASK_TIME_WINDOW_CONSTRAINT_TYPE;
    static const std::string START_ATTRIBUTE;
    static const std::string END_ATTRIBUTE;
    static const std::string TASK_LENGHT_CONSTRAINT_TYPE;
    static const std::string LENGHT_ATTRIBUTE;
    static const std::string RESOURCE_CAPACITY_CONSTRAINT_TYPE;
    static const std::string CAPACITY_ATTRIBUTE;
    static const std::string TASK_RESOURCES_NEEDED_CONSTRAINT_TYPE;
    static const std::string RESOURCES_NEEDED_ATTRIBUTE;
    static const std::string MODEL_ALLOW_IDLE_CONSTRAINT_TYPE;
    static const std::string ALLOW_IDLE_ATTRIBUTE;
    static const std::string MODEL_MAX_TIME_CONSTRAINT_TYPE;
    static const std::string MAX_TIME_ATTRIBUTE;
    static const std::string TRUE_STRING;
    static const std::string FALSE_STRING;
    static const std::string MODEL_PRECEDENCE_CONSTRAINT_TYPE;
    static const std::string BEFORE_PRECEDENCE_ATTRIBUTE;
    static const std::string AFTER_PRECEDENCE_ATTRIBUTE;

    // Methods.
    // --------

    void ReadModel( QXmlStreamReader & a_xmlStream );

    void ReadTask       ( QXmlStreamReader & a_xmlStream );
    void ReadResource   ( QXmlStreamReader & a_xmlStream );
    void ReadConstraint ( QXmlStreamReader & a_xmlStream );

    void ReadModelAllowIdleConstraint( QXmlStreamAttributes & a_xmlAttributes );
    void ReadModelMaxTimeConstraint  ( QXmlStreamAttributes & a_xmlAttributes );
    void ReadModelPrecedenceConstraint( QXmlStreamAttributes & a_xmlAttributes );

    void ReadTaskConstraints( QXmlStreamReader & a_xmlStream, Task * a_task );
    void ReadTaskConstraint ( QXmlStreamReader & a_xmlStream, Task * a_task);
    void ReadTaskTimeWindowConstraint( QXmlStreamAttributes & a_xmlAttributes, Task * a_task );
    void ReadTaskLenghtConstraint    ( QXmlStreamAttributes & a_xmlAttributes, Task * a_task );
    void ReadTaskResourcesNeededConstraint ( QXmlStreamAttributes & a_xmlAttributes, Task * a_task );

    void ReadResourceConstraints ( QXmlStreamReader & a_xmlAttributes, Resource * a_resource );
    void ReadResourceConstraint  ( QXmlStreamReader & a_xmlAttributes, Resource * a_resource );
    void ReadResourceCapacityConstraint( QXmlStreamAttributes & a_xmlAttributes, Resource * a_resource );

    // Protect default constructor.
    XmlModelConnector();

    // Protect copy constructor.
    XmlModelConnector( const XmlModelConnector & a_other );

    // Protect operator =.
    XmlModelConnector & operator = ( const XmlModelConnector & a_other );
};

#endif // XMLMODELCONNECTOR_H
